import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;

import javax.swing.JCheckBox;
import javax.swing.JFrame;
import javax.swing.JTextField;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;


public class ChceckBoxFrame extends JFrame {
	
	private JTextField textField;
	private JCheckBox italicCheckbox;
	private JCheckBox boldCheckbox;
	
	public ChceckBoxFrame() {
		super("ChcecBoxFrame");
		setLayout(new FlowLayout());
		
		textField = new JTextField("Tutaj wpisz tekst",25);
		textField.setFont(new Font("Serif", Font.PLAIN, 12));
		add(textField);
		
		italicCheckbox = new JCheckBox("Italic");
		boldCheckbox = new JCheckBox("Bold");
		add(italicCheckbox);
		add(boldCheckbox);
		
		CheckBoxHandler handler = new CheckBoxHandler();
		italicCheckbox.addItemListener(handler);
		boldCheckbox.addItemListener(handler);
			
	
	}
	
	
	
	private class CheckBoxHandler implements ItemListener{
		Font font;

		@Override
		public void itemStateChanged(ItemEvent e) {
			if(italicCheckbox.isSelected() && boldCheckbox.isSelected()) {
				font = new Font("Serif", Font.BOLD + Font.ITALIC, 12);
			}
			else if(italicCheckbox.isSelected()) {
				font = new Font("Serif", Font.ITALIC, 12);
			}
			else if(boldCheckbox.isSelected()) {
				font = new Font("Serif", Font.BOLD, 12);
			}
			else {
				font = new Font("Serif", Font.PLAIN, 12);
			}
			
			textField.setFont(font);
			
		}
	}

}
